import { Component, OnInit } from '@angular/core';
import {OrderService} from "../order.service";
import {NzMessageService} from "ng-zorro-antd";
import {ActivatedRoute} from "@angular/router";

@Component({
  selector: 'app-logistics',
  templateUrl: './logistics.component.html',
  styleUrls: ['./logistics.component.scss'],
  providers: [OrderService]
})
export class LogisticsComponent implements OnInit {

  order_no;
  order_info;
  express;
  _isSpinning = true;

  constructor(private orderService: OrderService,
              private _message: NzMessageService,
              private route: ActivatedRoute) { }

  ngOnInit() {
    this.order_no = this.route.snapshot.params['id'];

    this.getOrderLogistics();
  }
  expressMessage="物流信息获取失败";
  getOrderLogistics() {
    this.orderService.getOrderLogistics(this.order_no).subscribe(res => {
      if (res.code === 200) {
        let address=res.data.address;
        let express_company=res.data.express_company;
        this.order_info = {
          name:address.name,
          mobile:address.mobile,
          express_name:express_company.name,
          express_no:res.data.express_no,
          province:address.province+address.city+address.district+address.detail
        };
        this.express = res.data.data;
        this._isSpinning = false;
      } else {
        let address=res.data.address;
        let express_company=res.data.express_company;
        this.order_info = {
          name:address.name,
          mobile:address.mobile,
          express_name:express_company.name,
          express_no:res.data.express_no,
          province:address.province+address.city+address.district+address.detail
        };
        this.expressMessage=res.data.message;
        //this.express = res.data.data;
        this._isSpinning = false;
        //this._message.create('error', res.message);
      }
    });
  }
}
